package com.celi.scs.common.entity.sys;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

/**
 * @Author jiangshengjun
 * @Date 2024/10/30
 * @Description 用户打卡数据
 */
@Data
@Table(name = "sys_dl_check_data")
@Entity
public class UserKqEntity {

    @Id
    private String checkId;
    // 打卡日期 yyyyMMdd格式
    private String checkInDate;
    private int id;
    private String userId;
    private String extId;
    private String checkType;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date checkTime;
    private String KqCheckData;
    private String employNum;
    private String employName;

    public UserKqEntity() {

    }

    public UserKqEntity(DlResponse.UserKqData userKqData) {
        this.checkId = IdUtil.getSnowflakeNextIdStr();
        this.id = userKqData.getId();
        this.userId = userKqData.getUserId();
        this.extId = userKqData.getExtId();
        this.checkType = userKqData.getCheckType();
        this.checkTime = DateUtil.date(userKqData.getCheckTime() * 1000);
        this.checkInDate = DateUtil.format(DateUtil.date(userKqData.getCheckTime() * 1000), "yyyy年MM月dd日");
        DlResponse.KqCheckData checkData = JSON.parseObject(userKqData.getCheck_data(), DlResponse.KqCheckData.class);
        String employNum = checkData.getEmployeeNum();
        if (StrUtil.isNotEmpty(employNum) && !StrUtil.startWith(employNum, "2")) {
            this.employNum = "2" + employNum;
        }
        this.employName = checkData.getMemberMame();
        this.KqCheckData = userKqData.getCheck_data();
    }
}
